#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,a[200005];
ll ans;
void violence(int p,int last1,int last2,ll sum){
    if(p==n+1){
        ans=max(ans,sum);
        return;
    }
    int x=0;
    if(a[p]==last1) x=last1;
    violence(p+1,a[p],last2,sum+x);
    x=0;
    if(a[p]==last2) x=last2;
    violence(p+1,last1,a[p],sum+x);
}
int main(){
    //>>>DON'T forget to DELETE the // of freopen<<<
    /*
    silu: sihu keyi dp
    raner tuibuchulai yushi violent dfs
    */
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        ans=0;
        violence(2,a[1],0,0);//cong 2 kaishi, jianshao yiban changshu
        printf("%lld\n",ans);
    }
    return 0;
}
